package com.leyou.task.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RedissonConfig {

    /**
     * 构建 Redisson的客户端
     * @param prop
     * @return
     */
    @Bean
    public RedissonClient redissonClientConfig(RedisProperties prop){
        //这种%s是字符串,%d是数字
        String address = "redis://%s:%d";
        Config config = new Config();
//        config.useClusterServers()集群
        config.useSingleServer().//单点
                setAddress(
                        String.format(address,prop.getHost(),prop.getPort()));
        return Redisson.create(config);
    }
}
